import { defineConfig } from 'vite'
import svgr from "vite-plugin-svgr";
import react from '@vitejs/plugin-react-swc'
import path from 'path'

export default defineConfig({
  plugins: [
    react({
      tsDecorators: true,
    }),
    svgr()
  ],
  define: {
    __BUILD_TIMESTAMP__: new Date().getTime(),
  },
  server: {
    host: '0.0.0.0', // 允许外部访问
    port: 5173, // 可选：指定端口
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@node': path.resolve(__dirname, '../node/src'),
      '@shared': path.resolve(__dirname, '../shared/src'),
    }
  },
  build: {
    rollupOptions: {
      // 排除所有node目录下的文件
      external: [/^@node\/.*/, /@\.\.\/node\/.*/],
    }
  },
})
